<template>
  <div id="baseMessage">
    <div class="body">
      <div class="title">
        <span>1<i style="opacity: .5;">/4</i></span>
        <span>
          <van-icon name="records-o" size="22" color="#1989fa;"/>&nbsp;基本信息
        </span>
      </div>
      <van-divider />
      <form>
        <div class="one">
          <h3>
            <span class="iconfont icon-bitian" style="color: #ec6661;"></span>
            <i style="opacity: .5;">[单选题]</i>
            请问您的年龄是?
            <van-tag type="warning" v-if="message[0].bool">您未完成此选项</van-tag>
          </h3>
          <input type="text" placeholder="请输入您的年龄" v-model="message[0].data">
        </div>
        <div class="two">
          <h3>
            <span class="iconfont icon-bitian" style="color: #ec6661;"></span>
            <i style="opacity: .5;">[单选题]</i>
            请问您的性别是?
            <van-tag type="warning" v-if="message[1].bool">您未完成此选项</van-tag>
          </h3>
          <select v-model="message[1].data">
            <option value="0">男</option>
            <option value="1">女</option>
            <option value="2">保密</option>
          </select>
        </div>
        <div class="three">
          <h3>
            <span class="iconfont icon-bitian" style="color: #ec6661;"></span>
            <i style="opacity: .5;">[单选题]</i>
            请问您的残疾类型是?
            <van-tag type="warning" v-if="message[2].bool">您未完成此选项</van-tag>
          </h3>
          <input type="text" placeholder="请输入您的残疾类型" v-model="message[2].data">
        </div>
        <div class="four">
          <h3>
            <span class="iconfont icon-bitian" style="color: #ec6661;"></span>
            <i style="opacity: .5;">[单选题]</i>
            请问您目前的月收入是?
            <van-tag type="warning" v-if="message[3].bool">您未完成此选项</van-tag>
          </h3>
          <input type="text" placeholder='如"无收入"可填"无"' v-model="message[3].data">
        </div>
        <div class="five">
          <h3>
            <span class="iconfont icon-bitian" style="color: #ec6661;"></span>
            <i style="opacity: .5;">[单选题]</i>
            请问您的残疾原因是?
            <van-tag type="warning" v-if="message[4].bool">您未完成此选项</van-tag>
          </h3>
          <van-field
              v-model="message[4].data"
              rows="2"
              autosize
              type="textarea"
              maxlength="150"
              placeholder="请输入您残疾的原因"
              show-word-limit
              style="
              border: 1px solid rgba(0, 0, 0,.6);
              "
              />
        </div>
      </form>
    </div>
    <div class="tapBar">
      <div class="tapBarBox">
        <button :disabled="isdisabled" @click="skip" type="buttom">下一页</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      message: [
        { data: '', bool: false },
        { data: '', bool: false },
        { data: '', bool: false },
        { data: '', bool: false },
        { data: '', bool: false }
      ],
      isSkip: [],
      isdisabled: false,
      timer: null
    }
  },
  methods: {
    skip () {
      this.isSkip = JSON.parse(localStorage.getItem('baseMessage'))
      if (this.isSkip === null) {
        this.message.forEach(item => {
          item.bool = true
        })
        this.isdisabled = true
        this.timer = setTimeout(() => {
          this.message.forEach(item => {
            item.bool = false
          })
          this.isdisabled = false
        }, 2000)
        return
      }

      if (this.message.find((item) => item.data.length === 0)) {
        this.isdisabled = true
        this.message.forEach(item => {
          if (item.data.length === 0) {
            item.bool = true
          }
        })

        this.timer = setTimeout(() => {
          this.message.forEach(item => {
            item.bool = false
          })
          this.isdisabled = false
        }, 2000)
        return
      }

      this.$router.push('/survey/useSituation')
    }
  },
  created () {
    if (localStorage.getItem('baseMessage')) this.message = JSON.parse(localStorage.getItem('baseMessage'))
  },
  watch: {
    message: {
      deep: true,
      handler (newVal) {
        localStorage.setItem('baseMessage', JSON.stringify(newVal))
      }
    }
  }
}
</script>

<style scoped>
form .one input,
form .two select,
form .three input,
form .four input{
  margin: 0 20px;
  padding: 5px 10px;
  width: 300px;
  border: 1px solid rgba(0, 0, 0,.8);
  outline: none;
  color: rgba(0, 0, 0,.8);
  margin-bottom: 15px;
}
</style>
